package p.ithorns.integration.hazelcast.config;

import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import p.ithorns.integration.hazelcast.mqtt.LocalMqttClient;
import p.ithorns.integration.hazelcast.mqtt.MqttClientProps;
import p.ithorns.integration.hazelcast.mqtt.MqttMessageDispatcher;

/**
 * 依赖于网关MQTT服务端之后启动
 */
@Configuration
@EnableConfigurationProperties(MqttClientProps.class)
public class MqttGateConfig {

    @Bean(destroyMethod = "destroy")
    public LocalMqttClient initMqttClient(MqttClientProps props, MqttMessageDispatcher messageListener) throws MqttException {
        final LocalMqttClient instance = LocalMqttClient.getInstance();
        instance.init(props, messageListener);
        return instance;
    }

}